home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / HARDWARE.SWG / 0029_286-8088 code.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-25  |  2KB  |  48 lines

  1. {
  2. SE>I have Borland Pascal 7.0 and I ran acrost the idea of 286 and 8088 code
  3. SE>specs in a program.  How can you detect for a 286 CPU and if present,
  4. SE>switch $G to $G+ ?
  5.  
  6.  There should be a program somewhere in your TP disks that has a routine
  7.  that detects whether or not a 286+ CPU is pressent. Unfortunately you
  8.  can't have it change the status of $G. It's either on or off. You can
  9.  either leave it on , detect CPU type, if its the wrong type leave a
  10.  mesage and abort the program or not use the $G directive at all.
  11.  
  12.  Here is a simple CPU detection routine in case you can't find the one I
  13.  mentioned:
  14. }
  15.  
  16. CONST
  17.       CPU     :ARRAY[0..3] Of STRING[13] =('8088/V20','80286',
  18.                                           '80386/80486','80486');
  19. FUNCTION CpuType :WORD; ASSEMBLER;
  20.                  {  Returns a value depending on the type of CPU        }
  21.                  {          0 = 8088/V20 or compatible                  }
  22.                  {          1 = 80286    2 = 80386/80486+               }
  23. ASM
  24.   Xor DX,DX                             {  Clear DX                     }
  25.   Push DX
  26.   PopF                                  {  Clear Flags                  }
  27.   PushF
  28.   Pop AX                                {  Load Cleared Flags           }
  29.   And AX,$0F000                         {  Check hi bits for F0h        }
  30.   Cmp AX,$0F000
  31.   Je @Quit                              {  Quit if 8088                 }
  32.   Inc DX
  33.   Mov AX,$0F000                         {  Now Check For 80286          }
  34.   Push AX
  35.   PopF
  36.   PushF
  37.   Pop AX
  38.   And AX,$0F000                         {  If The top 4 bits aren't set }
  39.   Jz @Quit                              {  Its a 80286+                 }
  40.   Inc DX                                {  Else its a 80386 or better   }
  41. @Quit:
  42.   Mov AX,DX                             {  Return Result in AX          }
  43. END;{CpuType}
  44.  
  45. BEGIN
  46.   Writeln('Your CPU is a ',CPU[CpuType]);
  47. END.
  48.